﻿using Hjt212Parser;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DataProcessorDust.EF
{
    public class FacadeBufferInfoAndUtil
    {
        private static ILog Log = LogManager.GetLogger(typeof(FacadeBufferInfoAndUtil));

        private static List<MonitoringEquipment> portList = null;
        public static MonitoringEquipment Port(string mn)
        {
            try
            {
                if (portList == null || MyTimer.IsToTheTime("FacadeBufferInfoAndUtil.Port", 10))
                {
                    using (var ctx = new LampblackMonitorEntities())
                    {
                        portList = ctx.MonitoringEquipments.AsNoTracking().ToList();
                    }
                }

                return portList.Where(t => t.设备代码MN.Equals(mn)).FirstOrDefault();
            }
            catch (Exception e)
            {
                Log.Error(e);
                return null;
            }
        }

        private static List<MonitorFactorCode> factorList = null;

        public static MonitorFactorCode Factor(string code)
        {
            try
            {
                if (factorList == null || MyTimer.IsToTheTime("FacadeBufferInfoAndUtil.Factor", 10))
                {
                    using (var ctx = new LampblackMonitorEntities())
                    {
                        factorList = ctx.MonitorFactorCodes.AsNoTracking().ToList();
                    }
                }

                return factorList.Where(t => t.因子代码.Equals(code)).FirstOrDefault();
            }
            catch (Exception e)
            {
                Log.Error(e);
                return null;
            }
        }

        public static string ConvertFanStatus(string value)
        {
            switch (value)
            {
                case "0":
                    return "开";

                case "1":
                    return "关";
            }

            return "-";
        }

        public static string ConvertPurifierStatus(int? value)
        {

            if (value.HasValue)
            {
                return "开";
            }

            return "关";
        }
    }
}
